import React, { Component } from 'react'
import { CSSTransition, TransitionGroup } from 'react-transition-group'
import './Transition3.css'

export default class Transition3 extends Component {
  constructor() {
    super();
    this.state = {
      list: [
        'eat', 'sleep', 'coding'
      ]
    }
  }
  del(index) {
    let arr = this.state.list;
    arr.splice(index, 1);
    this.setState({
      list: arr
    })
  }
  render() {
    return (
      <div>
        <TransitionGroup>
          {
            this.state.list.map((item, index) => {
              return (
                <CSSTransition
                  key={index}
                  timeout={500}
                  classNames="item"
                >
                  <div className="div1">
                    <button onClick={()=>this.del(index)}>X</button>
                    <span>{item}</span>
                  </div>
                </CSSTransition>
              )
            })
          }
        </TransitionGroup>
      </div>
    )
  }
}
